package br.mg.bhe.ftpobre.command;

import java.io.File;

import br.mg.bhe.ftpobre.gui.MainFrame;
import br.mg.bhe.ftpobre.gui.fs.CreateFolderFrame;
import br.mg.bhe.ftpobre.log.FtpLogView;

/***
 * 
 * @author Aureliano
 */
public class CreateFolderLocalCommand implements ICommand {

	@Override
	public void execute() {
		if (this.canExecute()) {
			this.doAction();
		}
	}

	@Override
	public boolean canExecute() {
		return !MainFrame.getInstance().getLocalFilePath().isEmpty();
	}

	private void doAction() {
		String folderPath = MainFrame.getInstance().getAbsolutePathFromLocalFilePath() +
				"/" + CreateFolderFrame.getCandidateFolderName();
		File file = new File(folderPath);
		FtpLogView.log("Criando nova pasta...");
		file.mkdir();
		FtpLogView.log("Pasta '" + file.getAbsolutePath() + "' criada.");
	}
}